angular.module("myApp")
.controller("NewsController",
    function($scope,Demo,NewsService,$state){
      $scope.demo = new Demo();
     // 页面加载是首页展示要闻数据
       //点击资讯分类,获取数据
      document.getElementsByClassName("news_nav")[0].onclick = function(e){
        var nj = e.target.getAttribute("nt");
        var n = document.querySelectorAll(".news_nav a")
        //样式改变
        for(i=0;i<n.length;i++){
          n[i].setAttribute("class", "");
        }
        e.target.setAttribute("class", "news_active") 


         NewsService.getData0(nj).success(function(res){
              $scope.demo.items = res.data.rows;
           })
      } 
     $scope.login = function(){
      document.getElementsByClassName("news_head")[0].style.display = "none";
      document.getElementsByClassName("news_kinds")[0].style.display = "none";
      document.getElementsByClassName("news_nav")[0].style.display = "none";
     } 
     $scope.newShow = function(){
      document.getElementsByClassName("news_head")[0].style.display = "none";
      document.getElementsByClassName("news_nav")[0].style.display = "none";
      document.getElementsByClassName("news_list")[0].style.display = "none";
     } 
     $scope.news_back = function(){
      document.getElementsByClassName("news_head")[0].style.display = "block";
      document.getElementsByClassName("news_nav")[0].style.display = "flex";
      document.getElementsByClassName("news_kinds")[0].style.display = "block";
     }
})
.factory('Demo',function($http){
  var Demo = function () {
    this.items = [];
    this.busy = false;
    this.after = '';
    this.page = 1;
  };
  Demo.prototype.nextPage = function () {
    if (this.busy) return;
    this.busy = true;
    var url = "./data/news_data/news_010"+this.page+".json";
    $http.get(url).success(function (res) {
      var items = res.data.rows;
      for (var i = 0; i < items.length; i++) {
        this.items.push(items[i]);
      }
      this.busy = false;
      this.page += 1;
    }.bind(this));
  };
  return Demo;
})